home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / UI / StdDispM.cpp < prev    next >
Encoding:
Text File  |  1996-08-28  |  46.4 KB  |  1,471 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StdDispM.cpp
  3.  
  4.     Contains:    Implementation of standard dispatch module for Macintosh events
  5.  
  6.     Owned by:    Chris Linn
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <6>     8/14/96    CSL        1378142: Mouse-up causes crash if mouse-
  13.                                     down facet is invalid
  14.          <5>     6/22/96    EL        1344140: make sure menu is unhighlighted if
  15.                                     error is thrown.
  16.          <4>     6/21/96    CSL        1330394: Mouse-up doesn't get to frame
  17.                                     embedded in selection. 1330894: Mouse
  18.                                     events outside active shape of root frame
  19.                                     are not delivered. 1337817: modified mouse
  20.                                     events not delivered to floating windows.
  21.          <3>     6/14/96    eeh        1358680: send menuevent when F-[1…4]
  22.                                     pressed
  23.          <2>     6/12/96    eeh        1308137: send fake menuevent when
  24.                                     command-key is invalid
  25.         <48>    10/10/95    DM        1277216: GM:API: Dont return ODPoint from
  26.                                     GetWindowPoint()
  27.         <47>    10/10/95    RR        1289924    Now get kODEvtMouseUpEmbedded with
  28.                                     bundled embedded frames
  29.         <46>     9/21/95    RR        #1286167 Suppress mouse up after bg
  30.                                     mousedown. Renamed fInvalidClick to
  31.                                     fSuppressMouseUp
  32.         <45>     9/13/95    DM        1277216 GM:API return no ODPoints nor
  33.                                     ODPolygons
  34.         <44>     9/12/95    DM        1280020 FB1 part trans dlg mem leaks
  35.         <43>     9/12/95    JBS        1283337 use TempOD<Object>s to make
  36.                                     refcounting exception safe
  37.         <42>     9/12/95    RR        Changed some somPrintfs
  38.         <41>     8/29/95    DM        1221778, 1276165: [ShowLinkUpdateAlert]
  39.                                     call LinkMgr SuspendResume()
  40.         <40>     8/29/95    RR        #1267251 handle synthesized activate events
  41.         <39>     7/26/95    DM        #1270320: Memory leak fixes.
  42.         <38>     6/28/95    RR        #1242642. Ref counting fixes
  43.         <37>     6/28/95    JBS        1262900 if click in icon view root frame,
  44.                                     pass to shell instead of Redispatch
  45.         <36>     6/26/95    TÇ        1242642 BB:Fix refcounting bugs
  46.         <35>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  47.                                     refcount is wrong in
  48.                                     ODRefCntObjectsomUninit.
  49.         <34>     6/20/95    JBS        1257315 change Facet::AcquireWindow to
  50.                                     GetWindow
  51.         <33>     6/15/95    RR        #1256879 Get->AcquireCurrentMenuBar
  52.         <32>     5/31/95    RR        #1251403 Release after AcquirePart
  53.         <31>     5/26/95    RR        #1251403: Multithreading naming support
  54.         <30>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  55.         <29>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  56.                                     refcount
  57.         <28>     5/15/95    RR        # 1249142 Added checks for NULL to
  58.                                     PropagateTheEvent
  59.         <27>     5/10/95    RR        # 1242893, 1245692 Fixed Mouse up
  60.                                     dispatching
  61.         <26>     5/10/95    JBS        1241913 ODPart::AdjustBorderShape is not
  62.                                     called with null shape; 1224727 Facet
  63.                                     hit-testing calls should take point param
  64.                                     in frame coords
  65.         <25>      5/2/95    RR        # 1226050 Added fLastBorderFrame.
  66.         <24>     4/28/95    RR        1211085 Remove 5$ comments
  67.         <23>      4/6/95    RR        #1220104 Use of ODObjectsAreEqual, #1211085
  68.                                     Remove 5$ comments
  69.         <22>      4/4/95    RR        1220104 Use ODObjectsAreEqual, 1227750
  70.                                     local coords for mouseUp
  71.         <21>     3/13/95    NP        1221979: Remove incorrect comment.
  72.         <20>     3/10/95    RR        # 1199122 Dispatch Null Menu Events
  73.         <19>      3/7/95    RR        # 122649 WindowToLocal on eventInfo->where
  74.         <18>      3/1/95    RR        # 1224776 Disabled dispatching of activate
  75.                                     events, since it interferes with floating
  76.                                     window strategy.
  77.         <17>     2/28/95    jpa        Removed a bit o' test code accidentally
  78.                                     left in [1220704]
  79.         <16>     2/24/95    jpa        Dispatch kODEvtBGMouseDown &
  80.                                     kODEvtBGMouseDownEmbedded [1220704]
  81.         <15>     2/22/95    RR        # 1213850 Dispatch menu events to root part
  82.                                     of active window if not handled by menu
  83.                                     focus
  84.         <14>     2/20/95    TÇ        #1221861 BB: Incomplete AOCE support needs
  85.                                     to be removed from OpenDoc
  86.         <13>     1/31/95    RR        # 1162080 delete facet iterator in
  87.                                     GetActiveFacetWithBorderUnderPoint
  88.         <12>     1/13/95    RR        Added eventInfo to event handling methods.
  89.                                     Remove calls to HandleEventInEmbedded
  90.         <11>     11/1/94    RR        #1196756 Don't call DialogSelect for
  91.                                     updates and activates
  92.         <10>    10/27/94    eeh        #1191434 for RR: handle dlogs with the
  93.                                     modal focus correctly
  94.          <9>    10/27/94    RR        # 1191434 Check for ViewAsIcon etc in
  95.                                     DispatchToFacetUnderPoint. No longer handle
  96.                                     dialog updates and activates
  97.          <8>    10/21/94    NP        1187682: TSM support.
  98.          <7>    10/18/94    RR        Check for null containing facet in
  99.                                     DispatchToFacetUnderPoint
  100.          <6>     9/30/94    RR        #1188888, #1171182 For mouse clicks,
  101.                                     respect icon views, selected and dragging
  102.                                     states.
  103.          <5>     9/20/94    RR        #1167854. Rewrote DispatchKeyDown so that
  104.                                     unmatched command keys are passed to part
  105.                                     as a keystroke
  106.          <4>      9/6/94    RR        #1183392. Call HandleEventInEmbedded where
  107.                                     appropriate
  108.          <3>     8/10/94    JBS        1179919: coordinate system bias changes
  109.          <2>     7/26/94    eeh        ODQDPoint->Point
  110.          <1>     6/24/94    RR        first checked in
  111.          <7>      5/4/94    SS        #1160449: fixes for ModalFocus dialogs
  112.          <6>      4/8/94    RR        #1144767
  113.          <5>      4/1/94    TÇ        #1154941: Get OpenDoc source to actually
  114.                                     compile for PowerPC
  115.          <4>     3/28/94    CG        1153547: Renamed XMPSessn.h to XMPSessM.h
  116.          <3>     3/16/94    RR        #1151144. Made global functions static
  117.          <2>     2/16/94    JA        Include new AltPoint.h.
  118.         <38>      2/7/94    NP        Tiger Team doings.
  119.         <37>      2/7/94    NP        Tiger Team doings.
  120.         <36>     1/21/94    RR        Restored Dispatch() signature
  121.         <35>     1/20/94    RR        Handle AOCE Mailer events
  122.         <34>     1/18/94    RR        Use scrolling focus for pageUp etc., add
  123.                                     propagation
  124.         <33>     1/15/94    RR        WinState.h->WinStat.h,
  125.                                     Dispatch.h->Disptch.h
  126.         <32>     1/15/94    RR        Updated DispatchMenuEvent (command no. is
  127.                                     no longer in event)
  128.         <31>     1/14/94    RR        Shift-click in active border beeps
  129.         <30>     1/11/94    TÇ        Init... changes
  130.         <29>     1/10/94    RR        Added HiliteMenu calls
  131.         <28>    12/20/93    RR        New init strategy
  132.         <27>    12/16/93    RR        Various methods respect modal focus. Update
  133.                                     and activate events in dialogs are handled.
  134.                                     DispatchToFacetUnderPoint became a member
  135.                                     function.
  136.         <26>    12/15/93    JBS        activeShape & window now in facet not frame
  137.         <25>    12/13/93    RR        Remove warning.
  138.         <24>     12/6/93    RR        Call WindowState->SuspendResume
  139.         <23>     12/3/93    CC        SuspendResume: Moved call to
  140.                                     ExportClipboard() into the shell; no longer
  141.                                     modifies its event parameter so shell can
  142.                                     post-process the event.
  143.         <22>     12/2/93    CC        SuspendResume: Catch errors thrown by
  144.                                     ExportClipboard().
  145.         <21>     12/2/93    RR        Fixed some bugs in handling of mouse events
  146.         <20>    11/24/93    CC        Call ExportClipboard() on suspend events
  147.         <19>    11/19/93    RR        Correctly set "handled"
  148.         <18>    11/19/93    RR        Use correct event codes. Handle command
  149.                                     keys. Dispatch mouse downs in title bar to
  150.                                     root part.
  151.         <17>    11/18/93    JBS        use activeFrame->AcquireWindow()
  152.         <16>    11/16/93    RR        Central Casting for CFront
  153.         <15>    11/16/93    RR        Quick hack in MouseDownInContent until
  154.                                     Frame/Facet/Active Border is sorted out
  155.         <14>    11/16/93    RR        Shell now constructs menu events. Also
  156.                                     update for cursor-tracking and idling
  157.         <13>    11/12/93    JBS        use Facets
  158.         <12>    10/27/93    RR        Use Window::AcquireFrameUnderPoint instead of
  159.                                     local routine.
  160.         <11>    10/12/93    PH        Do some cleanup for VodooMonkey
  161.         <10>     10/8/93    RR        Use IsXMPWindow
  162.          <9>     10/6/93    JA        Use new fixed-point XMPPoint.
  163.          <8>     10/1/93    RR        Ignore 0 result of MenuSelect()
  164.          <7>     9/16/93    RR        Menu event uses command number
  165.          <6>     9/15/93    RR        Use command number in menu event (currently
  166.                                     commented out)
  167.          <5>      9/3/93    JBS        updated to use new Layout class
  168.          <4>     8/24/93    TÇ        commented out ifdef PROTOTYPEBUILD so
  169.                                     implementation could use hit detection code
  170.                                     from prototype
  171.          <3>     8/24/93    RR        Got rid of some CFront warnings
  172.          <2>     8/11/93    RR        Included hit detection code from prototype,
  173.                                     for now
  174.          <1>     8/10/93    RCR        first checked in
  175.  
  176.     To Do:
  177.     In Progress:
  178. */
  179.  
  180. #ifndef _ALTPOINT_
  181. #include "AltPoint.h"            // Use C++ savvy ODPoint and ODRect
  182. #endif
  183.  
  184.  
  185. #ifndef _STDDISPM_
  186. #include "StdDispM.h"
  187. #endif
  188.  
  189. #ifndef _TEMPOBJ_
  190. #include <TempObj.h>
  191. #endif
  192.  
  193. #ifndef _ODSESSN_
  194. #include "ODSessn.xh"
  195. #endif
  196.  
  197. #ifndef SOM_ODDispatcher_xh
  198. #include "Disptch.xh"
  199. #endif
  200.  
  201. #ifndef SOM_ODWindow_xh
  202. #include "Window.xh"
  203. #endif
  204.  
  205. #ifndef SOM_ODFacet_xh
  206. #include "Facet.xh"
  207. #endif
  208.  
  209. #ifndef SOM_ODWindowState_xh
  210. #include "WinStat.xh"
  211. #endif
  212.  
  213. #ifndef SOM_ODMenuBar_xh
  214. #include "MenuBar.xh"
  215. #endif
  216.  
  217. #ifndef SOM_Module_OpenDoc_Commands_defined
  218. #include "CmdDefs.xh"
  219. #endif
  220.  
  221. #ifndef SOM_LinkMgr_xh
  222. #include <LinkMgr.xh>
  223. #endif
  224.  
  225. #ifndef SOM_ODArbitrator_xh
  226. #include "Arbitrat.xh"
  227. #endif
  228.  
  229. #ifndef SOM_ODPart_xh
  230. #include "Part.xh"
  231. #endif
  232.  
  233. #ifndef SOM_Module_OpenDoc_Foci_defined
  234. #include "Foci.xh"
  235. #endif
  236.  
  237. #ifndef SOM_ODFrame_xh
  238. #include "Frame.xh"
  239. #endif
  240.  
  241. #ifndef SOM_ODFrameFacetIterator_xh
  242. #include "FrFaItr.xh"
  243. #endif
  244.  
  245. #ifndef SOM_ODFacetIterator_xh
  246. #include "FacetItr.xh"
  247. #endif
  248.  
  249. #ifndef _DSPUTILM_
  250. #include "DspUtilM.h"
  251. #endif
  252.  
  253. #ifndef __EPPC__
  254. #include <EPPC.h>
  255. #endif
  256.  
  257. #ifndef __MENUS__
  258. #include <Menus.h>
  259. #endif
  260.  
  261. #ifndef __DIALOGS__
  262. #include <Dialogs.h>
  263. #endif
  264.  
  265. #ifndef __TOOLUTILS__
  266. #include <ToolUtils.h>
  267. #endif
  268.  
  269. #ifndef __TEXTSERVICES_
  270. #include "TextServices.h"
  271. #endif
  272.  
  273. #pragma segment ODStdDispatchModule
  274.  
  275. #define ODDebugMenuEvents 0
  276. #define ODDebugLayerEvents 0
  277. #define ODDebugTitleBarEvents 0
  278. #define ODLogEvents 0
  279.  
  280. //=====================================================================================
  281. // CONSTANTS
  282. //=====================================================================================
  283.  
  284. const short     kSuspendResumeMessage = 0x01;    // High byte suspend/resume event 
  285. const short     kClipConvertMask      = 0x02;    // Bit of message field clip conversion
  286. const short     kResumeMask           = 0x01;    // Resume vs. suspend mask
  287. const short     kMouseMovedMessage    = 0xFA;    // High byte mouse-moved event message
  288.  
  289. //----------------------------------------------------------------------------------------
  290. // Enumeration for ASCII Character Constants
  291. //----------------------------------------------------------------------------------------
  292.  
  293. enum EAsciiControlCode {
  294.     chBackspace = 8,                    // ASCII code for Backspace character  
  295.     chClear = 27,                        // ASCII code for Clear key (aka ESC)  
  296.     chDown = 31,                        // ASCII code for down arrow  
  297.     chEnd = 4,                            // ASCII code for the End key  
  298.     chEnter = 3,                        // ASCII code for Enter character  
  299.     chEscape = 27,                        // ASCII code for Escape (aka Clear) key  
  300.     chFunction = 16,                    // ASCII code for any function key  
  301.     chFwdDelete = 127,                    // ASCII code for forward delete  
  302.     chHelp = 5,                            // ASCII code for Help key  
  303.     chHome = 1,                            // ASCII code for the Home key  
  304.     chLeft = 28,                        // ASCII code for left arrow  
  305.     chPageDown = 12,                    // ASCII code for Page Down key  
  306.     chPageUp = 11,                        // ASCII code for Page Up key  
  307.     chReturn = 13,                        // ASCII code for Return character  
  308.     chRight = 29,                        // ASCII code for right arrow  
  309.     chSpace = 32,                        // ASCII code for Space character  
  310.     chTab = 9,                            // ASCII code for Tab character  
  311.     chUp = 30                            // ASCII code for up arrow
  312. };
  313.  
  314.  
  315. //----------------------------------------------------------------------------------------
  316. // Enumeration for Virtual Key Code Constants
  317. //----------------------------------------------------------------------------------------
  318.  
  319. enum EVirtualKeyCode {
  320.     kClearVirtualCode = 71,                // Clear key virtual code  
  321.     kEscapeVirtualCode = 53,            // Escape key virtual code  
  322.     kF10VirtualCode = 109,                // F10 virtual key code  
  323.     kF11VirtualCode = 103,                // F11 virtual key code  
  324.     kF12VirtualCode = 111,                // F12 virtual key code  
  325.     kF13VirtualCode = 105,                // F13 virtual key code  
  326.     kF14VirtualCode = 107,                // F14 virtual key code  
  327.     kF15VirtualCode = 113,                // F15 virtual key code  
  328.     kF1VirtualCode = 122,                // F1 virtual key code  
  329.     kF2VirtualCode = 120,                // F2 virtual key code  
  330.     kF3VirtualCode = 99,                // F3 virtual key code  
  331.     kF4VirtualCode = 118,                // F4 virtual key code  
  332.     kF5VirtualCode = 96,                // F5 virtual key code  
  333.     kF6VirtualCode = 97,                // F6 virtual key code  
  334.     kF7VirtualCode = 98,                // F7 virtual key code  
  335.     kF8VirtualCode = 100,                // F8 virtual key code  
  336.     kF9VirtualCode = 101,                // F9 virtual key code  
  337.     kFwdDelVirtualCode = 117            // Forward Delete virtual code
  338. };
  339.  
  340. //=====================================================================================
  341. // Class MacDispatchModule
  342. //=====================================================================================
  343.  
  344. //-------------------------------------------------------------------------------------
  345. // MacDispatchModule::MacDispatchModule
  346. //
  347. // Description
  348. //-------------------------------------------------------------------------------------
  349.  
  350. MacDispatchModule::MacDispatchModule()
  351. {
  352.     fArbitrator = kODNULL;
  353.     fWindowState = kODNULL;
  354.  
  355.     fMouseDownFacet = kODNULL;
  356. }
  357.  
  358. //-------------------------------------------------------------------------------------
  359. // MacDispatchModule::~MacDispatchModule
  360. //
  361. // Description
  362. //-------------------------------------------------------------------------------------
  363.  
  364. MacDispatchModule::~MacDispatchModule()
  365. {
  366. }
  367.  
  368. //-------------------------------------------------------------------------------------
  369. // MacDispatchModule::InitStandardDispatchModule
  370. //
  371. // Description
  372. //-------------------------------------------------------------------------------------
  373.  
  374. void MacDispatchModule::InitMacDispatchModule(Environment* ev, ODSession* session)
  375. {    
  376.     fSession = session;
  377.     // Cache tokenized focus names
  378.     fKeyFocusToken = fSession->Tokenize(ev, kODKeyFocus);
  379.     fMenuFocusToken = fSession->Tokenize(ev, kODMenuFocus);
  380.     fSelectionFocusToken = fSession->Tokenize(ev, kODSelectionFocus);
  381.     fModalFocusToken = fSession->Tokenize(ev, kODModalFocus);
  382.     fMouseFocusToken = fSession->Tokenize(ev, kODMouseFocus);
  383.     fScrollingFocusToken = fSession->Tokenize(ev, kODScrollingFocus);
  384.     
  385.     fLargeIconViewToken = fSession->Tokenize(ev, kODViewAsLargeIcon);
  386.     fSmallIconViewToken = fSession->Tokenize(ev, kODViewAsSmallIcon);
  387.     fThumbnailViewToken = fSession->Tokenize(ev, kODViewAsThumbnail);
  388.     
  389.     // Cache session globals for easy access
  390.     
  391.     fArbitrator = fSession->GetArbitrator(ev);
  392.     fWindowState = fSession->GetWindowState(ev);
  393.     fDispatcher = fSession->GetDispatcher(ev);
  394. }
  395.  
  396. //-------------------------------------------------------------------------------------
  397. // MacDispatchModule::Dispatch
  398. //
  399. // Description
  400. //-------------------------------------------------------------------------------------
  401.  
  402. ODBoolean MacDispatchModule::Dispatch(Environment* ev, ODEventData* event, ODEventInfo* eventInfo)
  403. {
  404.     ODEventType eventType = event->what;
  405.     
  406.     switch (eventType)
  407.     {
  408.         case nullEvent:
  409.             break;        // Currently handled in ODDispatcher
  410.             
  411.         case mouseDown:
  412.         case kODEvtBGMouseDown:
  413.             return this->DispatchMouseDownEvent(ev, event, eventInfo);
  414.             
  415.         case kODEvtMouseDownBorder:    // via Redispatch
  416.             return this->DispatchMouseDownInBorder(ev, event, eventInfo);     
  417.  
  418.         case kODEvtMouseDownEmbedded:
  419.         case kODEvtBGMouseDownEmbedded:
  420.             return this->DispatchMouseDownEmbedded(ev, event, eventInfo);     
  421.  
  422.         case kODEvtMouseUpEmbedded:
  423.             return this->DispatchMouseUpEmbedded(ev, event, eventInfo);     
  424.                     
  425.         case mouseUp:
  426.             return this->DispatchMouseUpEvent (ev, event, eventInfo);
  427.             
  428.         case keyDown:
  429.             return this->DispatchKeyDownEvent(ev, event, eventInfo);
  430.  
  431.         case autoKey:
  432.             return this->DispatchKeyDownEvent(ev, event, eventInfo);
  433.             
  434.         case keyUp:
  435.             return this->DispatchKeyUpEvent(ev, event, eventInfo);
  436.             
  437.         case updateEvt:
  438.             return this->DispatchUpdateEvent(ev, event);
  439.             
  440.         case activateEvt:
  441.             return this->DispatchActivateEvent(ev, event);
  442.             
  443.         case osEvt:
  444.             this->DispatchOSEvent(ev, event);
  445.             return kODTrue;
  446.     
  447.         case kHighLevelEvent:
  448.             break;    // Handled by shell
  449.                         
  450.         case kODEvtMenu:
  451.             return this->DispatchMenuEvent(ev, event, eventInfo);
  452.             
  453.         default:
  454.             return kODFalse;
  455.     }
  456.     return kODFalse;
  457. }
  458.  
  459. //-------------------------------------------------------------------------------------
  460. // MacDispatchModule::DispatchOSEvent
  461. // 
  462. // Description
  463. //-------------------------------------------------------------------------------------
  464.  
  465. void MacDispatchModule::DispatchOSEvent(Environment* ev, ODEventData* theEvent)
  466. {
  467.     unsigned char     typeOSEvent;
  468.     
  469.     // • Is it a multifinder event?
  470.     typeOSEvent = (unsigned char) ( theEvent->message >> 24 ) & 0x00FF;
  471.     
  472.     // • Switch on the type of OSEvent that occurred, high byte of message is event type
  473.     switch ( typeOSEvent ) 
  474.     {     
  475.         case kMouseMovedMessage:
  476.             this->MouseMoved(ev, theEvent);
  477.             break;
  478.             
  479.         case kSuspendResumeMessage:
  480.             this->SuspendResume(ev, theEvent);
  481.             break;
  482.     }
  483. }    
  484.  
  485. //-------------------------------------------------------------------------------------
  486. // MacDispatchModule::MouseMoved
  487. // 
  488. // Description
  489. //-------------------------------------------------------------------------------------
  490.  
  491. void MacDispatchModule::MouseMoved(Environment* ev, ODEventData* theEvent)
  492. {
  493.     ODUnused(theEvent);
  494.     
  495.     fDispatcher->InvalidateMouseRegion(ev);
  496. }
  497.  
  498. //-------------------------------------------------------------------------------------
  499. // MacDispatchModule::SuspendResume
  500. // 
  501. // Description
  502. //-------------------------------------------------------------------------------------
  503.  
  504. void MacDispatchModule::SuspendResume(Environment* ev, ODEventData* theEvent)
  505. {
  506.     fWindowState->SuspendResume(ev, theEvent);
  507.  
  508.     ODLinkManager* linkMgr = fSession->GetLinkManager(ev);
  509.     linkMgr->SuspendResume(ev, theEvent);
  510. }
  511.  
  512. //-------------------------------------------------------------------------------------
  513. // MacDispatchModule::DispatchMenuEvent
  514. // 
  515. // Description
  516. //-------------------------------------------------------------------------------------
  517.  
  518. ODBoolean MacDispatchModule::DispatchMenuEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  519. {
  520.     ODBoolean handled = kODFalse;
  521.  
  522.     long menuResult = theEvent->message;
  523.     short menu = HiWord(menuResult);
  524.     short item = LoWord(menuResult);
  525.  
  526.     TRY
  527.         
  528.     //if (menu != 0) // #
  529.     {
  530.         TempODFrame targetFrame = fArbitrator->AcquireFocusOwner(ev, fMenuFocusToken);
  531.         
  532. #if ODDebug && ODDebugMenuEvents
  533.     somPrintf("Menu Event %d, %d for frame %x\n",menu, item, (ODFrame*)targetFrame);
  534. #endif
  535.         
  536.         if ( targetFrame )
  537.         {
  538.             handled = this->DispatchTheEvent(ev, theEvent, targetFrame, kODNULL, eventInfo);
  539.         }
  540.         // Note: To support root menu items like Print. We could add a new focus for this
  541.         if (!handled)
  542.         {
  543.             TempODWindow window = fWindowState->AcquireActiveWindow(ev);
  544.             ODFrame* rootFrame = window ? window->GetRootFrame(ev) : kODNULL;
  545.             if (rootFrame && (rootFrame != targetFrame))
  546.             {
  547.                 TempODPart rootPart = rootFrame->AcquirePart(ev);
  548. #if ODDebug && ODLogEvents
  549.     LogEvent(theEvent, eventInfo, rootFrame, kODNULL);
  550. #endif
  551.                 handled = rootPart->HandleEvent(ev, theEvent, rootFrame, kODNULL, eventInfo);
  552.             }
  553.         }
  554.     }
  555.     //else
  556.     //    handled = kODTrue;
  557.     
  558.     CATCH_ALL
  559.         HiliteMenu(0);
  560.         RERAISE;
  561.     ENDTRY
  562.     
  563.     //if (handled)
  564.     HiliteMenu(0);
  565.  
  566.     return handled;
  567. }
  568.  
  569. //-------------------------------------------------------------------------------------
  570. // MacDispatchModule::DispatchMouseDownInContent
  571. // 
  572. // Description
  573. //-------------------------------------------------------------------------------------
  574.  
  575.     static ODBoolean IsContained(Environment* ev, ODFrame* frame, ODFrame* container)
  576.     {
  577.         if ( (frame == kODNULL) || (container == kODNULL))
  578.             return kODFalse;
  579.         if (ODObjectsAreEqual(ev, frame, container))
  580.             return kODTrue;
  581.             
  582.         ODFrame* tempFrame = frame;
  583.         ODFrame* tempContainer = kODNULL;
  584.         tempFrame->Acquire(ev);    // -- TÇ added
  585.         while (tempFrame != kODNULL)
  586.         {
  587.             tempContainer = tempFrame->AcquireContainingFrame(ev);
  588.             tempFrame->Release(ev); // -- TÇ added
  589.             if (ODObjectsAreEqual(ev, tempContainer, container))
  590.             {
  591.                 tempContainer->Release(ev); // -- TÇ added
  592.                 return kODTrue;
  593.             }
  594.             tempFrame = tempContainer;        
  595.         }
  596.         return kODFalse;
  597.     }
  598.     
  599.     static ODFacet* GetActiveFacet(Environment* ev, ODFrame* frame, ODWindow* window, ODPoint& windowPoint)
  600.     // Could be a frame method
  601.     // Return the facet of "frame" which contains the point, or kODNULL
  602.     {
  603.         ODFacet* foundFacet = kODNULL;
  604.         ODPoint framePoint;
  605.     
  606.         if ( frame && window )
  607.         {
  608.             ODFrameFacetIterator* iter = frame->CreateFacetIterator(ev);
  609.     
  610.             for (ODFacet* facet = iter->First(ev);
  611.                     iter->IsNotComplete(ev);
  612.                     facet = iter->Next(ev))
  613.             {
  614.                 {
  615.                     // get windowPoint in frame coords for hit-testing
  616.                     TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  617.                     framePoint = windowPoint;
  618.                     winToFrame->InvertPoint(ev, &framePoint);
  619.                 }
  620.                 if (ODObjectsAreEqual(ev, facet->GetWindow(ev), window)
  621.                     && facet->ContainsPoint(ev, &framePoint, kODNULL) )
  622.                 {
  623.                     foundFacet = facet;
  624.                     break;
  625.                 }
  626.             }
  627.     
  628.             delete iter;
  629.         }
  630.         return foundFacet;
  631.     }
  632.     
  633.     
  634.     static ODFacet* GetFirstFacetUnderPoint(Environment* ev, ODWindow* window, ODFacet* root, ODPoint& windowPoint)
  635.     {
  636.     // returns NULL, root or an embedded facet of root
  637.     
  638.         ODFacet* foundFacet = kODNULL;
  639.         ODPoint framePoint;
  640.     
  641.         if (window && root && (ODObjectsAreEqual(ev, root->GetWindow(ev),window)))
  642.         {
  643.             ODFacetIterator* t = root->CreateFacetIterator(ev, kODTopDown, kODFrontToBack);
  644.             TempODObject tempIterator(t); // DMc - ensure deletion despite return/exceptions
  645.     
  646.             ODFacet* facet = t->First(ev);
  647.             
  648.             // get windowPoint in frame coords for hit-testing
  649.             {
  650.                 TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  651.                 framePoint = windowPoint;
  652.                 winToFrame->InvertPoint(ev, &framePoint);
  653.             }
  654.  
  655.             if ( !facet->ContainsPoint(ev, &framePoint, kODNULL) )
  656.                 return kODNULL;
  657.     
  658.             for ( facet = t->Next(ev);
  659.                     t->IsNotComplete(ev);
  660.                     facet = t->Next(ev) )
  661.             {
  662.                 // get windowPoint in frame coords for hit-testing
  663.                 {
  664.                     TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
  665.                     framePoint = windowPoint;
  666.                     winToFrame->InvertPoint(ev, &framePoint);
  667.                 }
  668.                 if (facet->ContainsPoint(ev, &framePoint, kODNULL))
  669.                 {
  670.                     foundFacet = facet;
  671.                     break;
  672.                 }
  673.                 else
  674.                     t->SkipChildren(ev); 
  675.             }
  676.             // delete t; // now deleted by TempODObject
  677.         }
  678.         if ( foundFacet )
  679.             return foundFacet;
  680.         else
  681.             return root;
  682.     }
  683.  
  684. ODBoolean MacDispatchModule::DispatchToFacetUnderPoint(Environment* ev, ODWindow* window, ODPoint& windowPt, 
  685.                                                     ODEventData* theEvent, ODEventInfo* eventInfo)
  686. {
  687.     ODBoolean handled = kODFalse;
  688.     
  689.     // Notes for bug 1330394
  690.     // ODWindow::GetFacetUnderPoint() skips child facets of a selected facet.  This is
  691.     // correct for mouse-down events, but not for mouse-up events that should activate
  692.     // a frame embedded in a selected facet.
  693.     // The fix is to call ODWindow::GetFacetUnderPointForDrag(), which does the same
  694.     // facet search but doesn't skip children of selected facets.  At a later, less
  695.     // heady date, we can change the method names to be GetFacetUnderPoint
  696.     // and GetFacetUnderPointNotSelected, or similar.
  697.     ODFacet* facet = kODNULL;
  698.     if ( theEvent->what == kODEvtMouseUp )
  699.         facet = window->GetFacetUnderPointForDrag(ev, &windowPt);
  700.     else
  701.         facet = window->GetFacetUnderPoint(ev, &windowPt);
  702.  
  703.     // If no facet was found, it's because the root facet's active shape must be smaller 
  704.     // than the frame shape. Send the event to the root facet anyway because it needs to
  705.     // do window activation, etc. Bug 1330894.
  706.     if ( facet == kODNULL )
  707.         facet = window->GetRootFacet(ev);
  708.  
  709.     ODFrame* frame = facet ? facet->GetFrame(ev) : kODNULL;
  710.  
  711.     if (facet && frame)
  712.     {
  713.         TempODFrame modalFocus = fArbitrator->AcquireFocusOwner(ev, fModalFocusToken);
  714.         if ( modalFocus && !IsContained(ev, frame, modalFocus))
  715.         {
  716.             TempODPart part = modalFocus->AcquirePart(ev); // -- TÇ tempobj'd
  717.             if (part)
  718.             {
  719. #if ODDebug && ODLogEvents
  720.     LogEvent(theEvent, eventInfo, modalFocus, kODNULL);
  721. #endif
  722.                 handled = part->HandleEvent(ev, theEvent, modalFocus, kODNULL, eventInfo);
  723.             }
  724.         }
  725.         else
  726.         {
  727.             ODTypeToken frameView = frame->GetViewType(ev);
  728.             ODBoolean isFrozen = frame->IsFrozen(ev);
  729.             ODBoolean isSelected = facet->IsSelected(ev);
  730.             ODBoolean isIcon = (frameView == fLargeIconViewToken ||
  731.                                 frameView == fSmallIconViewToken ||
  732.                                 frameView == fThumbnailViewToken);
  733.             ODBoolean isDragging = frame->IsDragging(ev);
  734.             ODBoolean isMouseDown = (theEvent->what != mouseUp);
  735.  
  736.             if ( isFrozen 
  737.                 || isSelected && isMouseDown
  738.                 || isIcon
  739.                 || isDragging && !isMouseDown)
  740.             {
  741.                 //PRINT("Mouse Down or Up to container\n");
  742.                 switch( theEvent->what ) 
  743.                 {
  744.                     case mouseDown:            theEvent->what = kODEvtMouseDownEmbedded; break;
  745.                     case kODEvtBGMouseDown:    theEvent->what = kODEvtBGMouseDownEmbedded; break;
  746.                     default:                theEvent->what = kODEvtMouseUpEmbedded; break;
  747.                 }
  748.                 eventInfo->embeddedFrame = frame;
  749.                 eventInfo->embeddedFacet = facet;
  750.                 
  751.                 ODFacet* containingFacet = kODNULL;
  752.                 containingFacet = facet->GetContainingFacet(ev);
  753.                 
  754.                 
  755.                 if ( containingFacet == kODNULL )
  756.                     return kODFalse;  // pass to shell/containerApp if this is a root frame
  757.                 else
  758.                 {
  759.                     // Cache the mouse down facet for use in mouse up dispatching, except
  760.                     // if the facet is selected, in which case the mouse up should go to the facet
  761.                     // under the mouse, provided the container doesn't do a drag.
  762.                     if (isMouseDown && (isFrozen || isIcon))
  763.                     {
  764.                         fMouseDownFacet = containingFacet;
  765.                         fEmbeddedFacet = facet;
  766.                     }
  767.                     handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  768.                 }
  769.             }
  770.             else
  771.             {
  772.                 fMouseDownFacet = facet;
  773.                 handled = this->DispatchTheEvent(ev, theEvent, frame, facet, eventInfo);
  774.             }
  775.         }
  776.     }
  777.     return handled;
  778. }
  779.  
  780. ODBoolean MacDispatchModule::DispatchMouseDownInContent (Environment* ev, ODWindow* theWindow,
  781.                                                                 ODEventData* theEvent, ODEventInfo* eventInfo)
  782. {
  783.     ODBoolean handled = kODFalse;
  784.     ODFacet* activeFacet = kODNULL;
  785.  
  786.     ODPoint windowPt; 
  787.     theWindow->GetWindowPoint(ev, &theEvent->where, &windowPt);
  788.     
  789.     ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey)) != 0;
  790.     ODBoolean tooModified = ((theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  791.     modified = modified && !tooModified;
  792.     eventInfo->where = windowPt;
  793.  
  794.     TempODFrame activeFrame = fArbitrator->AcquireFocusOwner(ev, fSelectionFocusToken); // -- TÇ tempobj'd
  795.     if ((ODFrame*)activeFrame ) 
  796.         activeFacet = GetActiveFacetWithBorderUnderPoint(ev, activeFrame, theWindow, ODPoint(windowPt));
  797.         
  798.     if ( activeFacet ) // Mouse down in border
  799.     {
  800.         if( theEvent->what==kODEvtBGMouseDown )
  801.             handled = kODFalse;
  802.         else
  803.         {
  804.             theEvent->what = kODEvtMouseDownBorder;
  805.             eventInfo->embeddedFrame = activeFrame;
  806.             eventInfo->embeddedFacet = activeFacet;
  807.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  808.         }
  809.     }
  810.     else // Click not in border
  811.     {
  812.         if (modified)
  813.         {
  814.             ODFacet* rootFacet = activeFrame ? GetActiveFacet(ev, activeFrame, theWindow, windowPt) 
  815.                 : (ODFacet*) kODNULL;
  816.             ODFacet* facet = GetFirstFacetUnderPoint(ev, theWindow, rootFacet, windowPt);
  817.             // returns NULL, rootFacet or embeddedFrame
  818.             
  819.             if (facet)
  820.             {
  821.                 if (ODObjectsAreEqual(ev, facet, rootFacet))
  822.                 {
  823.                     fMouseDownFacet = rootFacet;
  824.                     handled = this->DispatchTheEvent(ev, theEvent, activeFrame, rootFacet, eventInfo);
  825.                 }
  826.                 else // frame is embedded in active frame
  827.                 {
  828.                     theEvent->what = (theEvent->what==kODEvtBGMouseDown) ? kODEvtBGMouseDownEmbedded
  829.                                                                          : kODEvtMouseDownEmbedded;
  830.                     eventInfo->embeddedFrame = facet->GetFrame(ev);
  831.                     eventInfo->embeddedFacet = facet;
  832.                     fMouseDownFacet = rootFacet;
  833.                     fEmbeddedFacet = facet;
  834.                     //handled = this->DispatchTheEvent(ev, theEvent, activeFrame, rootFacet, eventInfo);
  835.                     handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  836.                 }
  837.             }    
  838.             else if ( theWindow->IsFloating( ev ))    // Allow dispatch to floaters: #1337817
  839.             {
  840.                 // Assume that floating windows belong to the active part, so go ahead
  841.                 // and dispatch.
  842.                 handled = DispatchToFacetUnderPoint(ev, theWindow, windowPt, theEvent, eventInfo);
  843.             }
  844.             else if ( theWindow->IsActive( ev ))    // Modified click outside active frame
  845.             {
  846.                 SysBeep(2);
  847.                 fSuppressMouseUp = kODTrue;
  848.             }
  849.             else    // Window is not active
  850.             {
  851.                 // Do nothing
  852.                 // Don't suppress the mouse-up, so window activation will still occur
  853.                 //handled = kODTrue;
  854.                 ;
  855.             }
  856.         }
  857.         else // No modifiers
  858.         {
  859.             handled = DispatchToFacetUnderPoint(ev, theWindow, windowPt, theEvent, eventInfo);
  860.         }
  861.     }
  862.     return handled;
  863. } // MouseDownInContent
  864.  
  865. ODBoolean MacDispatchModule::DispatchMouseDownInBorder(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  866. {    
  867.     ODBoolean handled = kODFalse;
  868.     ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey) ||
  869.                           (theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  870.     
  871.     if (modified)
  872.     {
  873.         SysBeep(2); // Shift-click or Command-click in border
  874.         fSuppressMouseUp = kODTrue;
  875.         handled = kODTrue;
  876.     }
  877.     else
  878.     {    
  879.         ODFacet* containingFacet = eventInfo->embeddedFacet->GetContainingFacet(ev);
  880.         fMouseDownFacet = containingFacet;
  881.         
  882.         handled = this->DispatchTheEvent(ev, theEvent, containingFacet->GetFrame(ev), containingFacet, eventInfo);
  883.     }
  884.     return handled;
  885. }
  886.  
  887. ODBoolean MacDispatchModule::DispatchMouseDownEmbedded(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  888. {    
  889.     ODBoolean handled = kODFalse;
  890.  
  891.     ODFacet* containingFacet = eventInfo->embeddedFacet->GetContainingFacet(ev);
  892.  
  893.     // We don't cache mouse down facet here, because the mouse up goes to the embedded part in some cases
  894.     
  895.     handled = this->DispatchTheEvent(ev, theEvent, containingFacet->GetFrame(ev), containingFacet, eventInfo);
  896.  
  897.     return handled;
  898. }
  899.  
  900. ODBoolean MacDispatchModule::DispatchMouseUpEmbedded(Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  901. {    
  902.     ODBoolean handled = kODFalse;
  903.     
  904.     if (fSuppressMouseUp)
  905.     {
  906.         handled = kODTrue;
  907.     }
  908.     else
  909.     {
  910.         if (fMouseDownFacet && fEmbeddedFacet)
  911.             handled = this->DispatchTheEvent(ev, theEvent, fMouseDownFacet->GetFrame(ev), fMouseDownFacet, eventInfo);
  912.         else
  913.             handled = kODTrue;
  914.     }
  915.  
  916.     fMouseDownFacet = kODNULL;
  917.     return handled;
  918. }
  919.  
  920. //-------------------------------------------------------------------------------------
  921. // MacDispatchModule::DispatchMouseDownEvent
  922. // 
  923. // Description
  924. //-------------------------------------------------------------------------------------
  925.  
  926. ODBoolean MacDispatchModule::DispatchMouseDownEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  927. {
  928.  
  929.     ODBoolean handled = kODFalse;
  930.  
  931.     TempODFrame mouseFocusFrame = fArbitrator->AcquireFocusOwner(ev, fMouseFocusToken); 
  932.     if (mouseFocusFrame)
  933.     {
  934.         TempODPart part = mouseFocusFrame->AcquirePart(ev); 
  935.         if ((ODPart*)part)
  936.         {
  937. #if ODDebug && ODLogEvents
  938.     LogEvent(theEvent, eventInfo, mouseFocusFrame, fMouseDownFacet);
  939. #endif
  940.             handled = part->HandleEvent(ev, theEvent, mouseFocusFrame, fMouseDownFacet, eventInfo);
  941.         }
  942.         return handled;
  943.     }
  944.  
  945.     WindowPtr platformWindow = kODNULL;
  946.     TempODWindow aWindow = kODNULL;
  947.     short         partCode;
  948.     
  949.     fMouseDownFacet = kODNULL;
  950.     fEmbeddedFacet = kODNULL;
  951.     fSuppressMouseUp = kODFalse;
  952.     
  953.     partCode = FindWindow ( theEvent->where, &platformWindow );
  954.     
  955.     
  956.     if (platformWindow && fWindowState->IsODWindow(ev, platformWindow))
  957.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  958.     
  959.     // Handle only clicks in OD content if this is a bg click:
  960.     if( theEvent->what==kODEvtBGMouseDown )
  961.     {
  962.         fSuppressMouseUp = kODTrue;
  963.         if( aWindow==kODNULL || partCode!=inContent )
  964.             return kODFalse;
  965.     }
  966.     if (partCode == inMenuBar)
  967.     {
  968.         long menuResult = MenuSelect(theEvent->where);
  969.         
  970.         if (!TSMMenuSelect(menuResult))
  971.         {
  972.             theEvent->what = kODEvtMenu;        
  973.             theEvent->message = menuResult;
  974.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  975.         }
  976.     }
  977.     else if (aWindow)
  978.     {
  979.         switch (partCode)
  980.         {
  981.             case inContent:
  982.                 handled = this->DispatchMouseDownInContent(ev, aWindow, theEvent, eventInfo);
  983.                 break;
  984.                 
  985.             case inGoAway:
  986.                 if (TrackGoAway (platformWindow, theEvent->where))
  987.                     handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  988.                 else
  989.                     handled = kODTrue;
  990.                 break;
  991.                 
  992.             case inDrag:
  993.                 handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  994.                 break;
  995.  
  996.             case inGrow:
  997.                 handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  998.                 break;
  999.                 
  1000.             case inZoomIn:
  1001.             case inZoomOut:
  1002.                 if (TrackBox(platformWindow, theEvent->where, partCode))
  1003.                     handled = this->DispatchWindowEvent(ev, aWindow, partCode, theEvent, eventInfo);
  1004.                 else
  1005.                     handled = kODTrue;
  1006.                 break;
  1007.                 
  1008.             default:
  1009.                 break;
  1010.         }
  1011.     }
  1012.  
  1013.     return handled;
  1014.  
  1015. }    //    MacDispatchModule::DispatchMouseDownEvent
  1016.  
  1017. //-------------------------------------------------------------------------------------
  1018. // MacDispatchModule::DispatchWindowEvent
  1019. // 
  1020. // Description
  1021. //-------------------------------------------------------------------------------------
  1022.  
  1023. ODBoolean MacDispatchModule::DispatchWindowEvent(Environment* ev, ODWindow* window, short partCode, 
  1024.                                                     ODEventData* theEvent, ODEventInfo* eventInfo)
  1025. {
  1026.     ODBoolean handled = kODFalse;
  1027.  
  1028.     TempODFrame modalFocus = fArbitrator->AcquireFocusOwner(ev, fModalFocusToken);
  1029.     if (modalFocus && !IsContained(ev, window->GetRootFrame(ev), modalFocus))
  1030.     {
  1031.         TempODPart part = modalFocus->AcquirePart(ev); // -- TÇ tempobj'd
  1032.         if ((ODPart*)part)
  1033.         {
  1034. #if ODDebug && ODLogEvents
  1035.     LogEvent(theEvent, eventInfo, modalFocus, kODNULL);
  1036. #endif
  1037.             handled = part->HandleEvent(ev, theEvent, modalFocus, kODNULL, eventInfo);
  1038.         }
  1039.     }
  1040.     else
  1041.     {
  1042.         ODFacet* rootFacet = window->GetRootFacet(ev);
  1043.         ODFrame* rootFrame = window->GetRootFrame(ev);
  1044.     
  1045.         theEvent->what = kODEvtWindow; 
  1046.         theEvent->message = partCode;
  1047. #if ODDebug && ODDebugTitleBarEvents
  1048.         somPrintf("Title Bar Event for root frame %x\n", rootFrame);
  1049. #endif
  1050.         handled = this->DispatchTheEvent(ev, theEvent, rootFrame, rootFacet, eventInfo);
  1051.     }
  1052.     return handled;
  1053. }
  1054.  
  1055. //-------------------------------------------------------------------------------------
  1056. // MacDispatchModule::DispatchMouseUpEvent
  1057. // 
  1058. // Description
  1059. //-------------------------------------------------------------------------------------
  1060.  
  1061. ODBoolean MacDispatchModule::DispatchMouseUpEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1062. {
  1063.     ODBoolean handled = kODFalse;
  1064.     WindowPtr platformWindow = kODNULL;
  1065.     TempODWindow aWindow = kODNULL;
  1066.     short         partCode;
  1067.     
  1068.     TempODFrame mouseFocusFrame = fArbitrator->AcquireFocusOwner(ev, fMouseFocusToken); 
  1069.  
  1070.     if (fSuppressMouseUp)
  1071.     {
  1072.         handled = kODTrue;
  1073.     }
  1074.     else if (mouseFocusFrame)
  1075.     {
  1076.         TempODPart part = mouseFocusFrame->AcquirePart(ev); 
  1077.         if ((ODPart*)part)
  1078.         {
  1079. #if ODDebug && ODLogEvents
  1080.             LogEvent(theEvent, eventInfo, mouseFocusFrame, fMouseDownFacet);
  1081. #endif
  1082.             handled = part->HandleEvent(ev, theEvent, mouseFocusFrame, fMouseDownFacet, eventInfo);
  1083.         }
  1084.     }
  1085.     else
  1086.     {
  1087. #ifdef ODDebug    
  1088.         //somPrintf("Mouse Up\n");
  1089. #endif
  1090.  
  1091.         partCode = FindWindow ( theEvent->where, &platformWindow );
  1092.         ODBoolean modified = ((theEvent->modifiers & cmdKey) || (theEvent->modifiers & shiftKey)) != 0;
  1093.         ODBoolean tooModified = ((theEvent->modifiers & optionKey) || (theEvent->modifiers & controlKey) ) != 0;
  1094.         modified = modified && !tooModified;
  1095.         
  1096.         
  1097.         if (platformWindow)
  1098.             aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1099.         
  1100.         if (aWindow)
  1101.         {
  1102.             ODPoint windowPt;
  1103.             aWindow->GetWindowPoint(ev, &theEvent->where, &windowPt);
  1104.             
  1105.             eventInfo->where = windowPt;
  1106.             
  1107.             switch ( partCode )
  1108.             {
  1109.                     case inContent:
  1110.                         // if (!modified)    // #1242893: What if it is?
  1111.                         {
  1112.                             if (fMouseDownFacet)
  1113.                             {
  1114.                                 if (fEmbeddedFacet)
  1115.                                 {
  1116.                                     theEvent->what = kODEvtMouseUpEmbedded;
  1117.                                     eventInfo->embeddedFacet = fEmbeddedFacet;
  1118.                                     eventInfo->embeddedFrame = fEmbeddedFacet->GetFrame(ev);
  1119.                                     handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  1120.                                 }
  1121.                                 else 
  1122.                                     handled = this->DispatchTheEvent(ev, theEvent, fMouseDownFacet->GetFrame(ev), fMouseDownFacet, eventInfo);
  1123.                             }
  1124.                             else 
  1125.                                 handled = DispatchToFacetUnderPoint(ev, aWindow, windowPt, theEvent, eventInfo);
  1126.                         }
  1127.                         break;
  1128.                     
  1129.                     default:
  1130.                         break;
  1131.             }
  1132.         }
  1133.     }
  1134.  
  1135.     fMouseDownFacet = kODNULL;
  1136.     return handled;
  1137. }    //    MacDispatchModule::DispatchMouseUpEvent
  1138.  
  1139. //-------------------------------------------------------------------------------------
  1140. // MacDispatchModule::DispatchKeyDownEvent
  1141. // 
  1142. // Description
  1143. //-------------------------------------------------------------------------------------
  1144. typedef enum { kNotAnFKey, kDisabledFKey, kEnabledFKey } FKeyResult;
  1145.  
  1146. static void FakeMenuEvent( Environment* ev, ODDispatcher* disp )
  1147. {
  1148.     ODEventData fakeEvent;
  1149.     fakeEvent.what = kODEvtMenu;
  1150.     fakeEvent.message = 0L;        // are we sure parts will do the right thing?
  1151.     (void)disp->Redispatch( ev, &fakeEvent, kODNULL );
  1152. }
  1153.  
  1154. static FKeyResult ConvertKeyToFKeyMenuEvent( Environment* ev, ODEventData* theEvent,
  1155.         ODWindowState* ws )
  1156. {
  1157.     FKeyResult result = kNotAnFKey;
  1158.     char key = (char) (theEvent->message & charCodeMask) ;
  1159.     if ( key == 0x10 )            // function key
  1160.     {
  1161.         char keyCode = (theEvent->message & keyCodeMask) >> 8;
  1162.         ODCommandID commandID;
  1163.         switch( keyCode )
  1164.         {
  1165.             case 0x7A:
  1166.                 commandID = kODCommandUndo; break;
  1167.             case 0x78:
  1168.                 commandID = kODCommandCut; break;
  1169.             case 0x63:
  1170.                 commandID = kODCommandCopy; break;
  1171.             case 0x76:
  1172.                 commandID = kODCommandPaste; break;
  1173.             default:
  1174.                 commandID = 0;
  1175.         }
  1176.         if ( commandID != 0 )
  1177.         {
  1178.             TRY
  1179.                 ODMenuID menu;
  1180.                 ODMenuItemID item;
  1181.                 TempODMenuBar menuBar = ws->AcquireCurrentMenuBar(ev);
  1182.                 menuBar->GetMenuAndItem( ev, commandID, &menu, &item );    // can throw
  1183.                 ODPlatformMenu macMenu = menuBar->GetMenu( ev, menu );        // can throw
  1184.                 long enableFlags = (*macMenu)->enableFlags;
  1185.                 long mask = 0x00000001 | (0x00000001 << item);
  1186.                 enableFlags = enableFlags & mask;
  1187.                 if ( enableFlags == mask )        // are *both* bits set?
  1188.                 {
  1189.                     theEvent->message = menu << 16 | item;
  1190.                     result = kEnabledFKey;
  1191.                 }
  1192.                 else
  1193.                     result = kDisabledFKey;
  1194.             CATCH_ALL
  1195.                 // don't reraise!
  1196.             ENDTRY
  1197.         }
  1198.     }
  1199.     return result;
  1200. }
  1201.  
  1202. ODBoolean MacDispatchModule::DispatchKeyDownEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1203. {
  1204.     ODBoolean handled = kODFalse;
  1205.     const short kNotAllowed =  shiftKey | optionKey | controlKey;
  1206.     char key = (char) (theEvent->message & charCodeMask) ;
  1207.  
  1208.     FKeyResult F_KeyResult = ConvertKeyToFKeyMenuEvent( ev, theEvent,
  1209.             fWindowState );
  1210.  
  1211.     // if it's an F-key BUT is disabled, we have to drop it on the floor.  Parts
  1212.     // will not be expecting to get such menu events.  At the same time, they
  1213.     // should not be getting them as keydowns either, since they don't get anything
  1214.     // when users attempt to select dimmed menus.  So apart from sending the fake
  1215.     // menu event to tell parts to drop the clipboard focus we ignore this case.
  1216.     if ( F_KeyResult == kDisabledFKey )
  1217.     {
  1218.         FakeMenuEvent( ev, fDispatcher );
  1219.         handled = kODTrue;
  1220.     }
  1221.     else if ( F_KeyResult == kEnabledFKey ||
  1222.             ((theEvent->modifiers & cmdKey) && !(theEvent->modifiers & kNotAllowed)) )
  1223.     {
  1224.         long menuResult = F_KeyResult == kEnabledFKey ?
  1225.                 theEvent->message : MenuKey(key);
  1226.         short menu = HiWord(menuResult);
  1227.  
  1228.         if ( menu == 0 )     // Unmatched command keys, eg. Command-Period or Disabled Item
  1229.                             // Sent to part as keystroke
  1230.         {
  1231.             WASSERT( F_KeyResult == kNotAnFKey );        // shouldn't have gotten here that way
  1232.             // send a menuevent first so the part will relinquish the clipboard focus
  1233.             // as per the recipes.  Bug 1308137
  1234.             FakeMenuEvent( ev, fDispatcher );
  1235.  
  1236.             TempODFrame keyFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1237.             handled = this->DispatchTheEvent(ev, theEvent, keyFrame, kODNULL, eventInfo);
  1238.         }
  1239.         else    // Turn it into a menu event
  1240.         {
  1241.             theEvent->what = kODEvtMenu;        
  1242.             theEvent->message = menuResult;        // in the fkey case, already set
  1243.             handled = fDispatcher->Redispatch(ev, theEvent, eventInfo);
  1244.  
  1245.             if (!handled)    // Deal with Close as a special case
  1246.             {
  1247.                 short item = LoWord(menuResult);
  1248.                 TempODMenuBar menuBar = fWindowState->AcquireCurrentMenuBar(ev);
  1249.                 ODCommandID command = menuBar ? menuBar->GetCommand(ev, menu, item) : 0;
  1250.                 
  1251.                 if (command == kODCommandClose)
  1252.                 {
  1253.                     TempODWindow activeWindow = fWindowState->AcquireActiveWindow(ev);
  1254.                     ODFrame* rootFrame = activeWindow ? activeWindow->GetRootFrame(ev) : kODNULL;
  1255.                     TempODPart rootPart = rootFrame ? rootFrame->AcquirePart(ev) : kODNULL;  // -- TÇ tempobj'd
  1256.                     
  1257.                     if (rootPart)
  1258.                     {
  1259. #if ODDebug && ODLogEvents
  1260.     LogEvent(theEvent, eventInfo, rootFrame, kODNULL);
  1261. #endif
  1262.                         handled = rootPart->HandleEvent(ev, theEvent,rootFrame, kODNULL, eventInfo);
  1263.                     }
  1264.                 }
  1265.             }
  1266.         }
  1267.     }
  1268.     else    // Regular unmodified keystrokes
  1269.     {
  1270.         TempODFrame scrollingFrame = fArbitrator->AcquireFocusOwner(ev, fScrollingFocusToken);
  1271.         if (scrollingFrame && 
  1272.             ((key == chPageUp) || (key == chPageDown) || (key == chHome) || (key == chEnd)))
  1273.         {
  1274.             handled = this->DispatchTheEvent(ev, theEvent, scrollingFrame, kODNULL, eventInfo);
  1275.         }    
  1276.         
  1277.         if (!handled)
  1278.         {
  1279.             TempODFrame keyFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1280.             handled = this->DispatchTheEvent(ev, theEvent, keyFrame, kODNULL, eventInfo);
  1281.         }
  1282.     }
  1283.     return handled;
  1284. }    //    MacDispatchModule::DispatchKeyDownEvent
  1285.  
  1286. //-------------------------------------------------------------------------------------
  1287. // MacDispatchModule::DispatchKeyUpEvent
  1288. // 
  1289. // Description
  1290. //-------------------------------------------------------------------------------------
  1291.  
  1292. ODBoolean MacDispatchModule::DispatchKeyUpEvent (Environment* ev, ODEventData* theEvent, ODEventInfo* eventInfo)
  1293. {
  1294.     ODBoolean handled = kODFalse;
  1295.     {
  1296.         TempODFrame targetFrame = fArbitrator->AcquireFocusOwner(ev, fKeyFocusToken);
  1297.         handled = this->DispatchTheEvent(ev, theEvent, targetFrame, kODNULL, eventInfo);
  1298.     }    
  1299.     return handled;
  1300. }    
  1301.  
  1302. //-------------------------------------------------------------------------------------
  1303. // MacDispatchModule::DispatchUpdateEvent
  1304. // 
  1305. // Description
  1306. //-------------------------------------------------------------------------------------
  1307.  
  1308. ODBoolean MacDispatchModule::DispatchUpdateEvent (Environment* ev, ODEventData* theEvent)
  1309. {
  1310.     ODBoolean handled = kODFalse;
  1311.     
  1312.     WindowPtr platformWindow = (WindowPtr) theEvent->message;
  1313.     TempODWindow aWindow = kODNULL;
  1314.     
  1315.     if (platformWindow && fWindowState->IsODWindow(ev, platformWindow))
  1316.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1317.     
  1318.     if ( aWindow )
  1319.     {
  1320.         aWindow->HandleUpdateEvent(ev, theEvent);
  1321.         handled = kODTrue;
  1322.     }
  1323.     return handled;
  1324. }    //    MacDispatchModule::DispatchUpdateEvent
  1325.  
  1326. //-------------------------------------------------------------------------------------
  1327. // MacDispatchModule::DispatchActivateEvent
  1328. // 
  1329. // Description
  1330. //-------------------------------------------------------------------------------------
  1331.  
  1332. ODBoolean MacDispatchModule::DispatchActivateEvent    (Environment* ev, ODEventData* theEvent)
  1333. {
  1334.     ODBoolean handled = kODFalse;
  1335.  
  1336.     WindowPtr platformWindow = (WindowPtr) theEvent->message;
  1337.     TempODWindow aWindow = kODNULL;
  1338.     
  1339.     if (platformWindow)
  1340.         aWindow = fWindowState->AcquireODWindow(ev, platformWindow);
  1341.  
  1342.     if (aWindow )
  1343.     {
  1344. #if ODDebug && ODDebugLayerEvents
  1345.     //if ( ((WindowPeek)platformWindow)->windowKind != dialogKind)
  1346.     //{ 
  1347.         if ((theEvent->modifiers & activeFlag) != 0)
  1348.             somPrintf("Ignoring Activate Event from event loop for root frame %x\n", aWindow->GetRootFrame(ev));
  1349.         else
  1350.             somPrintf("Ignoring Deactivate Event from event loop for root frame %x\n", aWindow->GetRootFrame(ev));
  1351.     //}
  1352. #endif
  1353.         // Note: Ignoring activate events solves the following problem:
  1354.         // When using the Drafts dialog to select an existing draft,
  1355.         // the dialog would generate an activate event for the window below it
  1356.         // when closed. The shell then opens the selected draft which brings its 
  1357.         // window to the front using ODWindow::Select (i.e. no events).
  1358.         // But then the activate event  comes in for the window which is no
  1359.         // longer frontmost.
  1360.  
  1361.         // Bit 1 (starting from 0) of the modifiers field is set in ODWindow::Activate/Deactivate 
  1362.         // to alert the dispatcher that this is an OpenDoc-generated activate event. Toolbox-generated
  1363.         // activates are ignored.
  1364.  
  1365.         if (IsODActivateEvent(*theEvent))
  1366.         {
  1367. #if ODDebug && ODDebugLayerEvents
  1368.         if ((theEvent->modifiers & activeFlag) != 0)
  1369.             somPrintf("OD Activate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1370.         else
  1371.             somPrintf("OD Deactivate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1372. #endif
  1373.             aWindow->HandleActivateEvent(ev, theEvent);
  1374.         }
  1375.         else
  1376.         {
  1377. #if ODDebug && ODDebugLayerEvents
  1378.         if ((theEvent->modifiers & activeFlag) != 0)
  1379.             somPrintf("MacOS Activate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1380.         else
  1381.             somPrintf("MacOS Deactivate Event for root frame %x\n", aWindow->GetRootFrame(ev));
  1382. #endif
  1383.         }
  1384.         
  1385.         handled = kODTrue;
  1386.     }
  1387.     return handled;    
  1388. }    //    MacDispatchModule::DispatchActivateEvent
  1389.  
  1390. //-------------------------------------------------------------------------------------
  1391. // MacDispatchModule::DispatchTheEvent
  1392. // 
  1393. // Dispatches the event to the initial target, or to a containing frame/facet,
  1394. // if the initial target doesn't handle it, and the containing part has
  1395. // set the "DoesPropagateEvents" flag of the embedded frame
  1396. //-------------------------------------------------------------------------------------
  1397.  
  1398. ODBoolean MacDispatchModule::DispatchTheEvent(Environment* ev, 
  1399.                             ODEventData* theEvent, 
  1400.                             ODFrame* targetFrame,
  1401.                             ODFacet* targetFacet,
  1402.                             ODEventInfo* eventInfo)
  1403. {
  1404.     ODBoolean handled = kODFalse;
  1405.     TempODPart targetPart = targetFrame ? targetFrame->AcquirePart(ev) : kODNULL; // -- TÇ tempobj'd
  1406.  
  1407.     if ((ODPart*)targetPart)
  1408.     {
  1409.         if (eventInfo && targetFacet)
  1410.             WindowToLocal(ev, eventInfo->where, targetFacet);
  1411. #if ODDebug && ODLogEvents
  1412.     LogEvent(theEvent, eventInfo, targetFrame, targetFacet);
  1413. #endif
  1414.         if (eventInfo && eventInfo->embeddedFrame)
  1415.         {
  1416.             handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1417.         }
  1418.         else
  1419.             handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1420.         if (!handled)
  1421.         {
  1422.             handled = PropagateTheEvent(ev, theEvent,targetFrame, targetFacet, eventInfo);
  1423.         }
  1424.     }
  1425.     return handled;
  1426. }
  1427.  
  1428. ODBoolean MacDispatchModule::PropagateTheEvent(Environment* ev, 
  1429.                             ODEventData* theEvent, 
  1430.                             ODFrame* initialFrame,
  1431.                             ODFacet* initialFacet,
  1432.                             ODEventInfo* eventInfo)
  1433. {    
  1434.     ODFacet* targetFacet = initialFacet;
  1435.     TempODFrame targetFrame = initialFacet ? initialFacet->GetFrame(ev) : initialFrame; // DMc refcount - temp
  1436.     // ODPart* targetPart = initialFrame ? initialFrame->AcquirePart(ev) : kODNULL; // Appears to be obsolete -TÇ
  1437.     ODBoolean handled = kODFalse;
  1438.         
  1439.     targetFrame->Acquire(ev);    // -- TÇ added
  1440.     while (targetFrame)
  1441.     {
  1442.         if (handled  || (!targetFrame->DoesPropagateEvents(ev)))
  1443.             break;
  1444.             
  1445.         if (targetFacet)
  1446.         {
  1447.             targetFacet = targetFacet->GetContainingFacet(ev);
  1448.             ODReleaseObject(ev, targetFrame); // DMc: about to reassign
  1449.             targetFrame = targetFacet ? targetFacet->GetFrame(ev) : kODNULL;
  1450.         }
  1451.         else
  1452.         {
  1453.             ODFrame* contFrame = targetFrame->AcquireContainingFrame(ev);     // -- TÇ added
  1454.             ODReleaseObject(ev, targetFrame);                                // -- TÇ added
  1455.             targetFrame = contFrame;
  1456.         }
  1457.         
  1458.         {    
  1459.             TempODPart targetPart = targetFrame ? targetFrame->AcquirePart(ev) : kODNULL; // -- TÇ tempobj'd
  1460.             if ((ODPart*)targetPart)
  1461.             {
  1462.                 eventInfo->propagated = kODTrue;
  1463.                 handled = targetPart->HandleEvent(ev, theEvent, targetFrame, targetFacet, eventInfo);
  1464.             }
  1465.         }
  1466.     }
  1467.         
  1468.     return handled;
  1469. }
  1470.  
  1471.